package com.example.computer_exam_training_sys.mapper;

import com.example.computer_exam_training_sys.entity.PaperQuestion;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface PaperQuestionMapper {
    // 查询所有试卷题目关联
    @Select("SELECT * FROM paper_questions")
    List<PaperQuestion> getAllPaperQuestions();

    // 根据试卷ID查询题目关联
    @Select("SELECT * FROM paper_questions WHERE paper_id = #{paperId} ORDER BY question_order ASC")
    List<PaperQuestion> getQuestionsByPaperId(Integer paperId);

    // 批量插入试卷题目
    @Insert({
            "<script>",
            "INSERT INTO paper_questions (paper_id, question_id, question_order, score) VALUES",
            "<foreach collection='list' item='pq' separator=','>",
            "(#{pq.paperId}, #{pq.questionId}, #{pq.questionOrder}, #{pq.score})",
            "</foreach>",
            "</script>"
    })
    int insertBatch(@Param("list") List<PaperQuestion> list);

}